package com.mybatis.mock;

import com.mybatis.domain.Blog;
import com.mybatis.domain.Comment;
import com.mybatis.domain.User;

import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Mock {

    public static User newUser() {
        User user = new User();
        user.setId(68L);
        String s = System.currentTimeMillis() + "";
        user.setName("mock_" + s);
        user.setLoginName("mock_login_" + s);
        user.setPassword(s);
        return user;
    }

    public static Comment newComment() {
        Comment comment = new Comment();
        comment.setBlogId(68);
        comment.setUserName(newUser().getName());
        comment.setBody("im body");
        return comment;
    }

    public static Blog newBlog() {
        Blog blog = new Blog();
        blog.setId(68);
        blog.setAuthor(newUser());
        blog.setBody("im body");
        blog.setTitle("im title");
        blog.setComments(
                Stream.iterate(newComment(), i -> newComment())
                       .limit(10)
                       .collect(Collectors.toList())
        );
        return blog;
    }
}
